package tcln.sors.client.core.mvc.modelmapping;

import java.util.List;

import tcln.sors.client.core.mvc.ListModelData;
import tcln.sors.client.core.mvc.ModelData;

/**
 * Interface for a mapper which maps an arbitary object to a {@link ModelData}.
 * 
 * @author Truong Chau Lien Ngoc (lienngoc@gmail.com)
 */
public interface ModelDataMapper {

    /**
     * maps an object to a given {@link ModelData}.
     * 
     * @param <M>
     * @param obj
     * @param targetModel
     *            Target model. This model must be instanciated before mapping.
     * @return
     */
    <M extends ModelData<?>> M map(Object obj, M targetModel);

    /**
     * maps an object to a {@link ModelData}.
     * 
     * @param <M>
     * @param obj
     * @param targetModelClass
     *            Target model class. This class must have a <i>default</i> constructor which is necessary to create
     *            model data instance. The visibility of this default constructor is, however, ignored.
     * @return
     */
    <M extends ModelData<?>> M map(Object obj, Class<M> targetModelClass);

    /**
     * maps many objects to a {@link ListModelData} whose each child is a {@link ModelData} corresponding to an object.
     * 
     * @param <M>
     * @param objects
     * @param targetChildModelClass
     *            Target class for all child models. This class must have a <i>default</i> constructor which is
     *            necessary to create models' instance. The visibility of this default constructor is, however, ignored.
     * @return
     */
    <M extends ModelData<?>> ListModelData<M> map(List<?> objects, Class<M> targetChildModelClass);
}
